/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package evaluation;

import OpenCOM.*;
/**
 *
 * @author Tinoo
 */
public class ReconfigExprEvaluator
{
    protected OpenCOM runtime = null;
    private IOpenCOM runtimeInterface = null;
    protected IMetaInterception metaInterception = null;
    int creationIndex = 0;

    protected int m_threshold;

    public ReconfigExprEvaluator()
    {
        runtime = new OpenCOM();
	runtimeInterface = (IOpenCOM)runtime.QueryInterface("OpenCOM.IOpenCOM");
        metaInterception = (IMetaInterception)runtime.QueryInterface("OpenCOM.IMetaInterception");
    }

    public void EvaluateExpression()
    {

    }

    void ParseExpression(String expression, int threshold)
    {

    }

    void PrintExpressionTree()
    {

    }

    void CreateHardwiredExpr()
    {
        IUnknown adder1 = CreateInterceptedComponent("expressions.Adder", "expressions.IExpression");
        IUnknown adder2 = CreateInterceptedComponent("expressions.Adder", "expressions.IExpression");
        IUnknown mult1 = CreateInterceptedComponent("expressions.Multiplier", "expressions.IEspression");
        IUnknown mult2 = CreateInterceptedComponent("expressions.Multiplier", "expressions.IEspression");
        IUnknown value2 = CreateComponent("expressions.Value", "expression.IExpression");
        value2.
        IUnknown value5 = CreateComponent("expressions.Value", "expression.IExpression");
        IUnknown value7 = CreateComponent("expressions.Value", "expression.IExpression");
    }
    
    public Object PostMethod(String method, Object result, Object [] args, Exception e)
    {
        return result;
    }

    protected IUnknown CreateComponent(String strClassName, String strInterfaceName)
    {
        //assign an unique name to our new component
        String ObjectName = strClassName.substring(strClassName.indexOf('.'+1));
        ObjectName += String.valueOf((creationIndex++));

        //create the component
        IUnknown component = (IUnknown) runtimeInterface.createInstance(strClassName, ObjectName);

        return component;
    }

    protected IUnknown CreateInterceptedComponent(String strClassName, String strInterfaceName)
    {
        //create the component
        IUnknown component = CreateComponent(strClassName, strInterfaceName);

        //add the interceptor
        IDelegator delegator = metaInterception.GetDelegator(component, strInterfaceName);
        delegator.addPostMethod(this, "PostMethod");
        
        return component;
    }
}
